<#include "../common/_layout.html" />
<@head title="角色分配">
<style type="text/css">
	.cll {
		background-color: #ddd;
	}
</style>
</@head>
<@layout menu='/admin'>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
				<form action="${ctx}/admin/roleAssignment?id=${admin.id}" id="listForm" method="post" role="form">
					<legend>角色分配</legend>
					<div class="form-group">
						
						姓名:<label for="adminname">${admin.username!}</label>
						<input type="hidden" class="form-control" id="adminSet_id"  name="adminSet_id" placeholder="" value="${admin.id!}">						
					</div>
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <tr class="info">
                                <th title="角色id"><input type="checkbox" id="allCheck"></th>
        
                                <th title="角色名">角色名</th>

                            </tr>
                            <#list page.getList() as role>
                                <tr>

                                    <td><input type="checkbox" name="ids" id="ids"  value="${role.id}" <#if  hasroles.contains(role)> checked="checked"</#if>></td> 

                                    <td>${role.name}</td>     
                                </tr>
                            </#list>
                        </table>
                    </div>
					<button type="button" class="btn btn-info" onclick="saveadminrole('${ctx}/adminrole/save')" >保存</button><button type="submit" class="btn btn-cancle" onclick="javascript :history.back(-1);">返回</button>
				</form>
			</div>
		</div>
	</div>
</section>
</@layout>
<@scripts>
<script type="text/javascript" src="${ctx}/adminlte/plugins/bootbox/bootbox.min.js"></script>
<script type="text/javascript" src="${ctx}/js/list.js"></script>
<script type="text/javascript">
function saveadminrole(url) {
	var roleid = $("#adminSet_id").val();
	var checkedresourceids = [];
	var allresourceids = [];
	$("input[name='ids']:checked").each(function(i) {
		checkedresourceids[i] = $(this).val();
	});
	$("input[name='ids']").each(function(i) {
		allresourceids[i] = $(this).val();
	});
	$.ajax({
		type : "post",
		url : url,
		data : {
			adminSet_id : roleid,
			ids : checkedresourceids,
			allids : allresourceids
		},
		dataType : "json",
		async : false,
		success : function(data) {
			bootbox.alert(data.message,function(){
				location.href="${ctx}/admin";
				
			});
		}
	});
}
	$(document).ready(function(){

	});
</script>
</@scripts>